package main

import (
	"go-ddd/config"
	"go-ddd/internal/common/core"
	"go-ddd/internal/common/logs"
	"go-ddd/internal/common/signals"
	"go-ddd/internal/servers"
	"go-ddd/internal/servers/rpc"
	"go-ddd/internal/servers/web"
)

func main() {
	cfg := config.NewConfig(config.FilePath())
	logs.Init(cfg.Log)
	core.Init()
	servers := NewServers(cfg)
	servers.AsyncStart()
	signals.WaitSignal(servers.Stop)
}

func NewServers(cfg *config.ConvertConfig) servers.ServerInterface {
	repos := servers.NewRepos(cfg)
	apps := servers.NewApps(repos)
	servers := servers.NewServers()
	servers.AddServer(web.NewWebServer(cfg, apps))
	servers.AddServer(rpc.NewRpcServer(cfg, apps))
	return servers
}
